package com.jinx.entity;

import com.jinx.converter.ImpressionConverter;
import com.jinx.domain.Impression;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Converter;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author Jinx
 * @date 2021/7/21 1:01
 */
@Entity
@Table(name = "tb_user")
@Data
@EntityListeners({AuditingEntityListener.class})
public class UserEntity {


    /**
     *  GenericGenerator : 自定义主键生成策略   strategy需要实现 IdentifierGenerator 接口
     *   同时需要和GeneratedValue一起使用，同时GeneratedValue的generator属性需要和name属性值一样
     */
    @Id
    @GeneratedValue(generator = "id")
    @GenericGenerator(name = "id", strategy = "com.jinx.config.JpaConfig")
    @Column(name = "id")
    private String id;

    @Column(name = "name")
    private String name;

    @Column(name = "wealth")
    private BigDecimal wealth;

    @Column(name = "info")
    private String info;

    @CreatedDate
    @Column(name = "create_time")
    private LocalDateTime createTime;

    @LastModifiedDate
    @Column(name = "update_time")
    private LocalDateTime updateTime;

    /**
     *  需要实现AuditorAware 接口获取当前用户
     */
    @CreatedBy
    @Column(name = "creator")
    private String creator;

    @LastModifiedBy
    @Column(name = "updater")
    private String updater;

    @Column(name = "deleted")
    private Integer deleted = 0;

    @Column(name = "remark")
    private String remark;


    @Column
    @Convert(converter = ImpressionConverter.class)
    private Impression impression;

    @OneToOne
    @JoinColumn(name = "husband_id")
    private HusbandEntity husbandEntity;
}
